package com.reliable.service.controller;

import com.reliable.api.dto.largescreen.*;
import com.reliable.api.param.largescrren.TransactionSuccessParam;
import com.reliable.common.core.domain.AjaxResult;
import com.reliable.service.service.ChatMessageService;
import com.reliable.service.service.ILargeScreenService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author yuyantao
 * ClassName: LargeScreenController
 * date: 2025/10/30 14:58
 */
@Api(value = "首页接口配置", tags = {"首页接口管理"})
@RestController
@RequestMapping("/reliable/largescreen")
public class LargeScreenController {

    @Autowired
    private ILargeScreenService largeScreenService;
    
    @Autowired
    private ChatMessageService chatMessageService;

    /**
     * 获取首页kpi数据展示
     */
    @ApiOperation("获取首页kpi数据展示")
    @PostMapping("/kpi")
    public AjaxResult getKpiData() {
        LargeScreenKpiData kpiData = largeScreenService.getKpiData();
        return AjaxResult.success(kpiData);
    }

    /**
     * 高风险会话日增量趋势图
     */
    @ApiOperation("高风险会话日增量趋势图")
    @PostMapping("/high-risk-session-trend")
    public AjaxResult getHighRiskSessionTrend() {
        List<RiskTrendData> trendData = largeScreenService.getHighRiskSessionTrendData();
        return AjaxResult.success(trendData);
    }

    /**
     * 可疑交易日新增趋势（趋势图）
     */
    @ApiOperation("可疑交易日新增趋势")
    @PostMapping("/suspect-transaction-trend")
    public AjaxResult getSuspectTransactionTrend() {
        List<RiskTrendData> trendData = largeScreenService.getSuspectTransactionTrendData();
        return AjaxResult.success(trendData);
    }

    /**
     * 可疑收款账户类型分布
     */
    @ApiOperation("可疑收款账户类型分布")
    @PostMapping("/collection-type-distribution")
    public AjaxResult getCollectionTypeDistribution() {
        List<CollectionTypeData> collectionTypeData = largeScreenService.getCollectionTypeData();
        return AjaxResult.success(collectionTypeData);
    }

    /**
     * 高风险会话的敏感词触发占比
     */
    @ApiOperation("高风险会话的敏感词触发占比")
    @PostMapping("/keyword-risk-ratio")
    public AjaxResult getKeywordRiskRatio() {
        KeywordRiskData keywordRiskData = largeScreenService.getKeywordRiskData();
        return AjaxResult.success(keywordRiskData);
    }

    /**
     * 交易成功率 vs 失败率
     */
    @ApiOperation("交易成功率vs失败率")
    @PostMapping("/transaction-success-ratio")
    public AjaxResult getTransactionSuccessRatio(@RequestBody TransactionSuccessParam param) {
        TransactionSuccessData transactionSuccessData = largeScreenService.getTransactionSuccessData(param.getStartTime(), param.getEndTime());
        return AjaxResult.success(transactionSuccessData);
    }

    /**
     * 获取最近事件列表
     */
    @ApiOperation("获取最近事件列表")
    @PostMapping("/recent-events")
    public AjaxResult getRecentEvents() {
        List<EventData> eventData = largeScreenService.getRecentEvents();
        return AjaxResult.success(eventData);
    }

    /**
     * 获取今日数据统计
     */
    @ApiOperation("获取今日数据统计")
    @PostMapping("/today-data")
    public AjaxResult getTodayData() {
        TodayData todayData = largeScreenService.getTodayData();
        return AjaxResult.success(todayData);
    }

    
    /**
     * 获取总览数据（包括PG和MySQL数据）
     */
    @ApiOperation("获取总览数据（包括PG和MySQL数据）")
    @PostMapping("/overview-data")
    public AjaxResult getOverviewData() {
        TotalOverviewData pgData = chatMessageService.getTotalOverviewData();
        TotalData totalData = new TotalData();
        totalData.setTotalMessages(pgData.getTotalMessages());
        totalData.setTotalSessions(pgData.getTotalSessions());
        totalData.setAnalyzedSessions(pgData.getAnalyzedSessions());
        totalData.setExtractedTransactions(largeScreenService.getExtractedTransactions());
        return AjaxResult.success(totalData);
    }

}